package org.megha.blog.example.morethreads;

/**
 * An enum with a single value is probably the ultimate singleton.
 * However, it can get real ugly real soon as far as testability is concerned.
 *
 * @author megha birmiwal
 */
public enum StatisticsCollector {
// can override methods in enums like this
//	INFLATED_STATS
//		public int getTimesCalled() {
//			return count * 10;
//		}
//	},
	STATS;

	private static int count = 0;
	private static double timeSum = 0;

	synchronized public void reportStat(double time) {
		count++;
		timeSum += time;
	}

	public int getTimesCalled() {
		return count;
	}

	public double getAverage() {
		return timeSum / getTimesCalled();
	}
}
